<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html lang="zh-cn" style="height: 100%">
<base href="<%=basePath%>">">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

	<title>卡账户充值</title>
	<link rel="stylesheet" href="css/base.css">
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript" src="js/base.js"></script>
	<script type="text/javascript" src="js/common.js"></script>
	<script type="text/javascript" src="js/handle.js"></script>
	<script type="text/javascript" src="js/sha256.js"></script>
	<script type="text/javascript" src="js/sig.js"></script>

	<script type="text/javascript">
		var orderNo = "${orderNo}"; // 订单号
		var cardNo = "${cardNo}"; //卡号
		var money = parseInt("${money}"); //充值金额 
		var orgBalance = parseInt("${orgBalance}"); //充值前余额
		var acctBalance = money + orgBalance; //充值后余额
		var vehiclePlate = "${vehiclePlate}";// 车牌号
		
		var token = "${token}";
		//alert(money)
		//alert(orgBalance)
		
		// 查询订单状态
		function rechargeConfirmation(orderNo) {
			$(".loading").show();			
			var data = {
				orderNo: orderNo
			};
			var time = (new Date()).valueOf();
			var sig_param = data;
			sig_param.time = time;
			sig_param.token = token;
			data.sig = reckonSig(sig_param);
			$.ajax({
				url: 'payment/confirm/' + time,
				type: 'POST',
				dataType: 'json',
				data: data,
				cache: false,
				timeout: 20000,
				success: function (r) {
					console.log(r)
					$(".loading").hide();			
					//alert(r.respCode);				
					if (r.respCode != "00" || r.in) {
						alert_LHX({
							hasBtn: 1,
							msg: "订单尚未到帐，请稍后重试"
						})
						return false;
					}
					//判断sig, 验证签名
					if(!r.sig){
						alert_LHX({
							hasBtn: 1,
							msg: '验证错误'
						})
						return;
					}

					var return_sig = r.sig;
					delete r.sig;

					var default_data = {
						token : token
					}
					var sig = reckonSigGet(default_data,r);
					if(return_sig != sig){
						alert_LHX({
							hasBtn: 1,
							msg: '验签失败'
						})
						return;
					}
					//alert("订单已到账");
					window.location.href = "transfer/toTransfer?cardNo="+cardNo+"&acctBalance="+acctBalance+"&vehiclePlate=" + vehiclePlate+"&payMoney="+money;

				},
				error: function(e) {
					$(".loading").hide();
					if (e.statusText == "timeout" || window.navigator.onLine == false) {
						alert_LHX({
							msg: "网络异常，请稍后重试！"
						})
						return false;
					}
					alert_LHX({
						msg: "服务器异常，请稍后重试！"
					})

				}

			});
		}
		$(function () {
			// 格式化数据并载入
			$("#cardNo").html("3601 " + cardNumFormat(cardNo));
			$("#orgBalance").html((orgBalance/100).toFixed(2))
			$("#rechargeMoney").html((money/100).toFixed(2))
			$("#balance").html((acctBalance/100).toFixed(2))

			// 点击圈存按钮
			$("#goToTransfer").click(function(e) {
				// 查询订单状态 到账则去圈存
				
				rechargeConfirmation(orderNo);

				
			});

		})
	</script>
</head>
<body class="">
	<div class="wrap">
		<div class="handle_result recharge_result">
			<h2>充值成功</h2>
			<div class="handle_result_box">
				<h3 class="border_e5"> <i class="result_card_icon"></i>
					<span id="cardNo">2342 2341 9387 2313 4927</span>
				</h3>
				<table  class="handle_result_table">
					<tbody>
						<tr>
							<td>充值前账户余额</td>
							<td>¥<span id="orgBalance"></span></td>


						</tr>
						<tr>
							<td>充值金额</td>
							<td>¥<span id="rechargeMoney"></span></td>
						</tr>
						<tr>
							<td>充值后账户余额</td>
							<td>¥<span id="balance"></span></td>
						</tr>
					</tbody>
				</table>
			</div>
			<div class="finishBtn recharge_result_btn" id="goToTransfer"> <i></i>
				账户余额足够了，快去圈存
			</div>
		</div>
	</div>
	<div class="mask_layer none"></div>
	<div class="toast toast_timeout" style="display:none">网络异常，请稍后重试！</div>
	<div class="toast toast_error" style="display:none">信息输入有误</div>
	<div class="loading" style="display:none">
		<img src="img/loading.gif"></div>
</body>
</html>